package com.example.demo.service.Impl;


import com.example.demo.bean.BaseUser;
import com.example.demo.bean.BaseUserExample;
import com.example.demo.dao.BaseUserMapper;
import com.example.demo.service.IBaseUserService;

import org.hibernate.validator.constraints.Range;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BaseUserServiceImpl  implements IBaseUserService {
    @Resource
    BaseUserMapper baseUserMapper;

    @Override
    public List<BaseUser> query (String username,String gender){

        BaseUserExample baseUserExample=new BaseUserExample();
        if (!StringUtils.isEmpty(username)) {
            baseUserExample.createCriteria().andUsernameLike("%" + username + "%");
        }
        if (!StringUtils.isEmpty(gender)) {
            baseUserExample.createCriteria().andGenderEqualTo(gender);
        }
        List<BaseUser> list = baseUserMapper.selectByExample(baseUserExample);
        return list;
    }
    @Override
    public String saveOrUpdate(BaseUser user){
        if (user.getId()!=null){
            baseUserMapper.updateByPrimaryKey(user);
            return "更新成功";
        }
        baseUserMapper.insert(user);
        return "保存成功";

    }
    @Override
    public void deleteById(long id){
        baseUserMapper.deleteByPrimaryKey(id);
    }

}
